// // 指数运算
// Math.pow(2, 3); // 8
// console.log(Math.pow(2, 5));

// let str = '123456789';
// // 字符串转数字
// console.log(+str[1]);

function ListNode(val, next) {
    this.val = (val === undefined ? 0 : val)
    this.next = (next === undefined ? null : next)
}

// 测试数据
let node1 = new ListNode(1);
let node2 = new ListNode(0);
let node3 = new ListNode(1);
node1.next = node2;
node2.next = node3;


var getDecimalValue = function (head) {
    let str = '';
    while (head) {
        str += head.val;
        head = head.next;
    }
    let len = str.length;
    console.log(str);

    let num = 0;
    let j = 0;
    for (let i = len - 1; i >= 0; i--) {
        console.log(+str[i], Math.pow(2, j));

        num += (+str[i] * Math.pow(2, j));
        j++;
    }
    return num;
};

console.log(getDecimalValue(node1));